﻿using System;
using System.Collections;
using com.bodurov.SessionRecovery.Tests.Utils;
using NUnit.Framework;

namespace com.bodurov.SessionRecovery.Tests
{
    [TestFixture]
    public class CommonWorkflowTestFixture
    {
        [Test]
        public void SaveAndRestore()
        {
            const string sessionID = "TestSession1";
            var initialSession = new Hashtable
                                     {
                                         {"KeyOne", "Somestring"},
                                         {"KeyTwo", 11},
                                         {"KeyThree", new SampleObject{ ID = 1, Name = "Sample Object 1" }}
                                     };

            TestHolder.Manager.IsEnabled = true;
            TestHolder.Manager.SaveIfEnabled(initialSession, sessionID);
            TestHolder.Manager.IsEnabled = false;
            var restoredSession = 
                TestHolder.Manager.RestoreIfExists(sessionID);

            Assert.IsNotNull(restoredSession);
            Assert.AreEqual(initialSession["KeyOne"], restoredSession["KeyOne"]);
            Assert.AreEqual(initialSession["KeyTwo"], restoredSession["KeyTwo"]);
            Assert.AreEqual(((SampleObject)initialSession["KeyThree"]).ID, ((SampleObject)restoredSession["KeyThree"]).ID);
            Assert.AreEqual(((SampleObject)initialSession["KeyThree"]).Name, ((SampleObject)restoredSession["KeyThree"]).Name);
        }

        [Serializable]
        public class SampleObject
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }
    }
}
